/**
 * Created by Administrator on 2017/9/19/0019.
 */
define(function (require) {
    var studentHandler = new require('userHandler').StudentHandler();
    var $=  require('jquery');
    require('jquery.cookie');

    function execute() {
        var allCoursesDom = document.getElementById('all-courses'),
            myCoursesDom = document.getElementById('my-courses'),
            allCoursesSum = document.getElementById('all-courses-sum'),
            myCoursesSum = document.getElementById('my-courses-sum');
        studentHandler.searchAllCourse(function (data) {
            allCoursesSum.innerHTML = data.length;
            for (var i in data){
                (function (data) {
                    console.log(data)
                    var node = document.createElement('div');
                    node.innerHTML = '<a href="javascript:void(0)">'+data.name+'</a>';
                    node.addEventListener('click',function () {
                       $.cookie('courseId',data.id);
                       location.reload();
                    });
                    allCoursesDom.appendChild(node);
                    console.log(node)
                }(data[i]));
            }
        });
        studentHandler.getAllCourse(function (data) {
            myCoursesSum.innerHTML = data.length;
            for (var i in data){
                (function (data) {
                    var node = document.createElement('div');
                    node.innerHTML = '<a href="javascript:void(0)">'+data.name+'</a>';
                    node.addEventListener('click',function () {
                        $.cookie('courseId',data.id);
                        location.reload();
                    });
                    myCoursesDom.appendChild(node);
                }(data[i]));
            }
        });

    }


    return{
        execute:execute
    }
})